/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.controller;


import cn.com.recloud.bbs.vo.AppCommentVO;
import cn.com.recloud.core.util.Result;
import cn.com.recloud.one.spring.exception.OneException;
import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import cn.com.recloud.one.spring.controller.BaseController;

import cn.com.recloud.bbs.entity.bbs_post_comment_log;
import cn.com.recloud.bbs.service.PostCommentLogService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author keblea xie
 * @date 2020-06-15
 */
@RestController
@RequestMapping("/api/bbs/postcommentlog")
@Api(tags = "文章评论相关接口")
public class PostCommentLogController extends BaseController<bbs_post_comment_log,PostCommentLogService> {
    @Resource
    PostCommentLogService postCommentLogService;


    @GetMapping("commentbyid/{id}")
    @ApiOperation("获取评论详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的id")
    })
    public Result commentById(@PathVariable("id") String id){
        if(StringUtils.isBlank(id)){
            throw new OneException("评论id不能为空");
        }
        return new Result(postCommentLogService.getCommentById(id));
    }

    @PostMapping("muldelcomment")
    @ApiOperation("批量删除评论及其子评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "评论id的集合")
    })
    public Result muldelComment(@RequestBody List<String> list){
        if(CollectionUtil.isEmpty(list)){
            throw new OneException("请至少选择一条要删除的记录");
        }
        postCommentLogService.mulDelComment(list);
        return Result.SUCCESS;
    }


    @GetMapping("listcomment/{id}")
    @ApiOperation("根据文章id查询评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "文章的id")
    })
    public Result appListComment(@PathVariable("id") String id) {
        List<AppCommentVO> list= postCommentLogService.appListComment(id);
        return new Result(list);
    }
}

